﻿namespace QLPhongKham.UC
{
    using ConfigDatabase.Class;
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraTab;
    using QLPhongKham.Access;
    using QLPhongKham.BaseClass.VienPhi;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class ucvp_chonquyenso : XtraUserControl
    {
        private ConnectDatabase _condata;
        private int _iiddangnhap;
        private int _iidquyenso;
        private General _xuli;
        private SimpleButton btnketthuc;
        private SimpleButton btnmoi;
        private LookUpEdit cbbtinhthanh;
        private IContainer components;
        private Label label3;

        public ucvp_chonquyenso()
        {
            this._iiddangnhap = 0;
            this._iidquyenso = 0;
            this.components = null;
            this.InitializeComponent();
            this._condata = new ConnectDatabase();
        }

        public ucvp_chonquyenso(ConnectDatabase condata, int iddangnhap)
        {
            this._iiddangnhap = 0;
            this._iidquyenso = 0;
            this.components = null;
            this.InitializeComponent();
            this._condata = condata;
            this._iiddangnhap = iddangnhap;
        }

        private void btnketthuc_Click(object sender, EventArgs e)
        {
            try
            {
                XtraTabPage parent = (XtraTabPage) base.Parent;
                XtraTabControl control = (XtraTabControl) parent.Parent;
                control.TabPages.Remove(parent);
            }
            catch
            {
                try
                {
                    XtraUserControl control2 = (XtraUserControl) base.Parent;
                    control2.Controls.Remove(this);
                }
                catch
                {
                    ((Form) base.Parent).Close();
                }
            }
        }

        private void btnmoi_Click(object sender, EventArgs e)
        {
            this._iidquyenso = Convert.ToInt32(this.cbbtinhthanh.EditValue);
            this.btnketthuc_Click(null, null);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void f_Loaddata_dmvp()
        {
            try
            {
                this.cbbtinhthanh.Properties.DataSource = new dtovpDMQuyenSo(this._xuli.pConFigData).LoadAll();
                this.cbbtinhthanh.Properties.DisplayMember = "ten";
                this.cbbtinhthanh.Properties.ValueMember = "id";
            }
            catch
            {
            }
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(ucvp_chonquyenso));
            this.label3 = new Label();
            this.btnmoi = new SimpleButton();
            this.btnketthuc = new SimpleButton();
            this.cbbtinhthanh = new LookUpEdit();
            this.cbbtinhthanh.Properties.BeginInit();
            base.SuspendLayout();
            this.label3.Font = new Font("Tahoma", 10f);
            this.label3.Location = new Point(5, 12);
            this.label3.Name = "label3";
            this.label3.Size = new Size(0x4c, 0x13);
            this.label3.TabIndex = 2;
            this.label3.Text = "Quyển sổ:";
            this.label3.TextAlign = ContentAlignment.TopRight;
            this.btnmoi.Appearance.Options.UseTextOptions = true;
            this.btnmoi.Appearance.TextOptions.HAlignment = HorzAlignment.Near;
            this.btnmoi.Image = Properties.Resources.imgnew;// (Image)manager.GetObject("btnmoi.Image");
            this.btnmoi.Location = new Point(0x5f, 0x26);
            this.btnmoi.Name = "btnmoi";
            this.btnmoi.Size = new Size(0x4b, 0x17);
            this.btnmoi.TabIndex = 1;
            this.btnmoi.Text = " &Chọn";
            this.btnmoi.Click += new EventHandler(this.btnmoi_Click);
            this.btnketthuc.Appearance.Options.UseTextOptions = true;
            this.btnketthuc.Appearance.TextOptions.HAlignment = HorzAlignment.Near;
            this.btnketthuc.Image = Properties.Resources.imgclose;// (Image)manager.GetObject("btnketthuc.Image");
            this.btnketthuc.Location = new Point(0xb0, 0x26);
            this.btnketthuc.Name = "btnketthuc";
            this.btnketthuc.Size = new Size(0x52, 0x17);
            this.btnketthuc.TabIndex = 2;
            this.btnketthuc.Text = " &Kết th\x00fac";
            this.btnketthuc.Click += new EventHandler(this.btnketthuc_Click);
            this.cbbtinhthanh.Location = new Point(0x54, 7);
            this.cbbtinhthanh.Name = "cbbtinhthanh";
            this.cbbtinhthanh.Properties.Appearance.Font = new Font("Tahoma", 10f);
            this.cbbtinhthanh.Properties.Appearance.Options.UseFont = true;
            this.cbbtinhthanh.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.cbbtinhthanh.Properties.Columns.AddRange(new LookUpColumnInfo[] { new LookUpColumnInfo("id", "id", 20, FormatType.None, "", false, HorzAlignment.Default), new LookUpColumnInfo("ten", "T\x00ean") });
            this.cbbtinhthanh.Properties.DropDownRows = 10;
            this.cbbtinhthanh.Properties.HeaderClickMode = HeaderClickMode.AutoSearch;
            this.cbbtinhthanh.Properties.HideSelection = false;
            this.cbbtinhthanh.Properties.HighlightedItemStyle = HighlightStyle.Standard;
            this.cbbtinhthanh.Properties.NullText = "";
            this.cbbtinhthanh.Properties.SearchMode = SearchMode.AutoComplete;
            this.cbbtinhthanh.Size = new Size(0xbb, 0x16);
            this.cbbtinhthanh.TabIndex = 0;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.cbbtinhthanh);
            base.Controls.Add(this.btnketthuc);
            base.Controls.Add(this.btnmoi);
            base.Controls.Add(this.label3);
            base.Name = "ucvp_chonquyenso";
            base.Size = new Size(0x117, 0x4b);
            base.Load += new EventHandler(this.ucDMSanPham_Load);
            base.KeyDown += new KeyEventHandler(this.ucDMSanPham_KeyDown);
            this.cbbtinhthanh.Properties.EndInit();
            base.ResumeLayout(false);
        }

        private void ucDMSanPham_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SendKeys.Send("{Tab}");
            }
            else if (e.KeyCode == Keys.F2)
            {
                if (this.btnmoi.Enabled)
                {
                    this.btnmoi_Click(null, null);
                }
            }
            else if ((e.KeyCode == Keys.F12) && this.btnketthuc.Enabled)
            {
                this.btnketthuc_Click(null, null);
            }
        }

        private void ucDMSanPham_Load(object sender, EventArgs e)
        {
            this._xuli = new General(this._condata);
            this.f_Loaddata_dmvp();
        }

        public int pIDQuyenSo
        {
            get
            {
                return this._iidquyenso;
            }
        }
    }
}

